#ifndef BASE_PTHREADPOOL_HPP
#define BASE_PTHREADPOOL_HPP

#include <mutex>
#include <base/defines.h>
#include <base/log.h>
#include <functional>
#include <condition_variable>
#include <thread>
#include <queue>
#include <base/Task.hpp>

#define THREAD_NUM 10


class PthreadPool {
    public:
        static PthreadPool* GetInstance();
        NONCOPYABLE(PthreadPool);
        IMMOVEABLE(PthreadPool);
        void PushTask(Task* const task);
        void PopTask(Task** task); 
        bool IsEmpty();
       
    private:
        PthreadPool(int thread_num);
        ~PthreadPool();
        static void PthreadFunc(void *prt);
        void InitPthreadPool();
        void PthreadPoolLock();
        void PthreadPoolUnlock();
        
    private:
        static PthreadPool* pthread_pool_instance_;
        static std::mutex mutex_;
        std::queue<Task*> queue_;
        std::condition_variable queue_is_empty_cond_;
        std::mutex  queue_mutex_;
        int thread_num_;
};

#endif